#include <REGX52.H>
#include "LCD1602.h"
#include "Delay.h"
#include "MatrixKey.h"

unsigned char KeyNum;
unsigned int PassWord;

int main()
{
	unsigned char count=0;
	LCD_Init();
	LCD_ShowString(1,1,"KeyNumber:");
	while(1)
	{
		KeyNum=MatrixKey();
		if(KeyNum)
		{
			if(KeyNum<=10)
			{
				if(count<4)
				{
					PassWord=PassWord*10+KeyNum%10;
					count++;
				}
				LCD_ShowNum(1,12,PassWord,4);
			}
			if(KeyNum==11)
			{
				if(PassWord==5259)
				{
					LCD_ShowString(2,1,"correct!");
					PassWord=0;
					count=0;
					LCD_ShowNum(1,12,PassWord,4);
				}
				else
				{
					LCD_ShowString(2,1,"wrong!  ");
					PassWord=0;
					count=0;
					LCD_ShowNum(1,12,PassWord,4);
				}
			}
			else if(KeyNum==12)
			{
				PassWord=0;
				count=0;
				LCD_ShowNum(1,12,PassWord,4);
			}
		}
	}
}